﻿/******************************************************************************
 * 【本类功能概述】                                 					      *
 *  版权所有（C）2020-20XX，                                        *
 *  保留所有权利。                                                            *
 ******************************************************************************
 *  作者 : <hughjk>
 *  创建时间:2019/11/25 0:29:06
 *  文件描述: 
 *****************************************************************************/
using System;
using System.Collections.Generic;
using UnityEngine;
using Util;
public class Bullet:MonoBehaviour
{
    public Vector3 dir;
    public float speed = 20;
    public Weapon weapon;
    public float m_harm = 10;
    public void Attack(Vector3 pos)
    {
        dir = pos - transform.position;
        Timer.Instance.Add(3, 1, () => {
            Over();
        });
    }

    private void Update()
    {
        transform.Translate(dir.normalized * speed * Time.deltaTime);
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        var s = collision.transform.GetComponent<Soldier>();
        if (s)
        {
            if (s._TeamType!= weapon.m_soldier._TeamType)
            {
                s._HP -= m_harm;
                Over();
            }
        }
    }
    bool isover = false;
    private void Over()
    {
        if (isover)
        {
            return;
        }
        isover = true;
        GameObject.Destroy(gameObject);
    }

}

